import "./public-path";
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

import drag from "vue-dragline";
import "vue-dragline/lib/vue-dragline.css";

import ViewUI from "view-design";
import "view-design/dist/styles/iview.css";
Vue.use(ViewUI);
Vue.use(drag);

Vue.config.productionTip = false;

let instance = null;
function render(props = {}) {
  const { container } = props;
  const el = container ? container.querySelector("#app") : "#app";

  instance = new Vue({
    router,
    store,
    render: (h) => h(App),
  }).$mount(el);
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap() {
  console.log("[vue] vue app bootstraped");
}
export async function mount(props) {
  console.log("主应用的传参", props);

  props.onGlobalStateChange((state, prev) => {
    // state: 变更后的状态; prev 变更前的状态
    console.log("onGlobalStateChange---------", state, prev);
  });

  setTimeout(() => {
    props.setGlobalState({
      initParams: 88888888,
    });
  }, 5000);

  render(props);
}
export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = "";
  instance = null;
}
